package com.smh.a12WaitThread1;

public class Foodile extends Thread {
    @Override
    public void run() {
        while (true) {
            synchronized (Desk.lock) {
                if (Desk.count == 0) {
                    break;
                }
                if (Desk.foodFlag > 0) {
                    Desk.count--;
                    System.out.println("还能再吃" + Desk.count + "碗");
                    Desk.foodFlag = 0;
                    Desk.lock.notifyAll();//唤醒厨师继续做.
                } else {
                    try {
                        Desk.lock.wait();//让当前进程跟锁进行绑定
                        //挂起
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        }
    }
}
